package Test_1030;

import java.util.ArrayList;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-10-30
 * Time: 22:53
 */
public class Test {
    public static void main(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.display();//1 2 3
        System.out.println();
        myArrayList.set(2,11);//1 2 11
        myArrayList.display();
        System.out.println();
        myArrayList.set(3,11);//报错
        myArrayList.display();
    }
    public static void main4(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.display();
        System.out.println();//1 2 3
        //移除:
        myArrayList.remove(2);
        myArrayList.display();
        System.out.println();//1 3
        myArrayList.remove(5);//没有该元素，移除失败
        System.out.println();
        //清空:
        myArrayList.clear();
        myArrayList.display();
        myArrayList.add(1);
        myArrayList.display();//1
    }
    public static void main3(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        //是否包含
        boolean b=myArrayList.contains(5);
        System.out.println(b);
        //获取下标元素
        int a=myArrayList.get(2);
        System.out.println(a);
        //获取元素下标
        int c=myArrayList.indexOf(0);
        System.out.println(c);
        int d=myArrayList.indexOf(3);
        System.out.println(d);
    }
    public static void main2(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(3,11);
        myArrayList.add(6,5);
        myArrayList.display();
    }
    public static void main1(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.display();
    }
}
